﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Util;
using System.Windows.Forms;
namespace GoogleWebRankExample
{
    class Program
    {
        static WebBrowser browser = new WebBrowser();
 
        [STAThread]
        static void Main(string[] args)
        {
            browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
            string query = "http://www.google.com/search?num=39&q={0}&btnG=Search";
            browser.Navigate(new Uri(string.Format(query,"rzeszow")));
            browser.Navigating += new WebBrowserNavigatingEventHandler(browser_Navigating);
            browser.Navigated += new WebBrowserNavigatedEventHandler(browser_Navigated);
            browser.Navigate("http://onet.pl");

            Console.ReadLine();

        }

        static void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {

            string html = browser.DocumentText;
            Uri url = new Uri("http://rzeszow.pl");
           // int result = FindPosition(html, url);
            //Console.WriteLine(result);
        }

        static void browser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            
        }

        static void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
        }
     

        /// <summary>
        /// Examins the search result and retrieves the position.
        /// </summary>
        //private static int FindPosition(string html, Uri url)
        //{
        //    string lookup = "(<a class=l href=\")(\\w+[a-zA-Z0-9.-?=/]*)";
        //    MatchCollection matches = Regex.Matches(html, lookup);

        //    for (int i = 0; i < matches.Count; i++)
        //    {
        //        string match = matches[i].Groups[2].Value;
        //        if (match.Contains(url))
        //            return i + 1;
        //    }
        //    return -1;
        //}
    }
}